package cn.ecut.controller;

import cn.ecut.model.*;
import cn.ecut.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.List;

@Controller
/*@RequestMapping(value = "/admin")*/
@SessionAttributes(value = {"applyList","repairsList"})//可添加多个session
public class AdminController {
    @Autowired
    AdminService adminService;

    @RequestMapping(value = "/adminLoginCheck")//验证登入
    public String loginCheck(@RequestParam(value = "username",required = true) String adminname,
                             @RequestParam(value = "password" ) String password){
        Admin admin=new Admin();
        admin.setAdminname(adminname);
        admin.setPassword(password);
        if(adminService.loginCheck(admin)!=null)
            return "admin/Central_Archives";//成功，进入管理员主页
        else
            return "admin/adminLogin";//错误，继续登入验证
    }

    @RequestMapping("/findAllApply")
    public String findAllApplyName(Model model){
        List<Dormitory> applyList = adminService.findAllApply();
        model.addAttribute("applyList",applyList);
        return "admin/Lease_management";
    }

    @RequestMapping("/findAllRepair")
    public String findAllRepair(Model model){
        List<Repair> repairsList = adminService.findAllRepair();
        model.addAttribute("repairsList",repairsList);
        return "admin/Report_for_repair";
    }

    @RequestMapping(value = "/findAllContract")
    public String findAllContract(Model model){
        List<Contract> contractList = adminService.findAllContract();
        model.addAttribute("contractList",contractList);
        return "";
    }
    @RequestMapping(value = "/findAllUser")
    public String findAllUser(Model model) {
        List<User> userList = adminService.findAllUser();
        model.addAttribute("userList",userList);
        return "";
    }

    public String findUserByCondition(@RequestParam("condition")  String condition ,
                                      Model model){
        User u = new User();
        User user = adminService.findUserByCondition(u);
        return "";
    }

    public String findContractByUser(){
        return "";
    }

    public String findALLRepair(){
        return "";
    }

}
